<?php
/**
 * Created by PhpStorm.
 * User: LQ
 * Date: 2018/4/11
 * Time: 16:22
 */

namespace app\common\third;

use \PHPMailer\PHPMailer\PHPMailer;

/*
 * 邮箱类
 * */
class Email
{

    const EMAIL_HOST = 'smtp.qq.com';
    const EMAIL_FROMNAME = '人人生活圈';
    const EMAIL_PASSWORD = 'nnkyuhchaufocjja';
    const EMAIL_USERNAME = '3428220153@qq.com';

    /*
     * 邮件发送接口
     * @params $to 目标地址
     * @params $subject 邮件标题
     * @params $to      邮件内容
     *
     * */
    public static function send($to,$subject,$content){
        vendor('phpmailer.phpmailer.src.PHPMailer');
        vendor('phpmailer.phpmailer.src.SMTP');
        $mail            = new PHPMailer(); //实例化phpmailer 核心类
        $mail->SMTPDebug = 0;
        $mail->isSMTP();
        $mail->SMTPAuth   = true;
        $mail->Host       = self::EMAIL_HOST;
        $mail->SMTPSecure = 'ssl';
        $mail->Port       = 465;
        $mail->Hostname   = '';
        $mail->CharSet    = 'UTF-8';
        $mail->Fromname   = self::EMAIL_FROMNAME;
        $mail->Username   = self::EMAIL_USERNAME;
        $mail->Password   = self::EMAIL_PASSWORD;
        $mail->From       = self::EMAIL_USERNAME;
        $mail->isHTML(true);
        $mail->addAddress($to);
        $mail->Subject = $subject;
        $mail->Body    = $content;
        try {
            $status  = $mail->send();
            return $status;
        } catch (Exception $e) {
            return false;
        }
    }
}